<template>
	<div class="dismissbox">
		<el-row>
			<el-tabs type="border-card">
				<el-tab-pane label="员工跨部门调职">
					<el-table :data="changes">
						<el-table-column prop="changeno" label="id"></el-table-column>
						<el-table-column prop="state" label="状态">
						</el-table-column> 
						<el-table-column prop="state" label="种类">
							<template slot-scope="scope">
								<i v-if="scope.row.state==0">调出本部门</i>
								<i v-else-if="scope.row.state==1">调入本部门</i>
							</template>
						</el-table-column> 
						<el-table-column prop="eid" label="员工"></el-table-column>
						<el-table-column prop="change_date" label="申请时间"></el-table-column>
						<el-table-column prop="pdname" label="之前部门"></el-table-column>
						<el-table-column prop="sdname" label="之后部门"></el-table-column>
						<el-table-column prop="preno" label="之前部门" v-if="false"></el-table-column>
						<el-table-column prop="subdno" label="之后部门" v-if="false"></el-table-column>
						<el-table-column prop="infro" label="infro" v-if="false" type="hidden"></el-table-column>
						<el-table-column label="操作">
							<template slot-scope="s">
								<el-button type="primary" @click="look(s.$index,s.row)">查看</el-button>
							</template>
						</el-table-column>
					</el-table> 
					<el-dialog title="跨部门调职处理" :visible.sync="dialogFormVisible">
						<el-form :model="form" label-width="100px">
							<el-form-item label="员工:">
								<el-input v-model="form.eid" autocoplete="off" disabled></el-input>
							</el-form-item>
							<el-form-item label="申请时间:">
								<el-date-picker type="date" placeholder="选择日期" format="yyyy-M-d" value-format="yyyy-M-d" v-model="form.change_date" style="float:left;" disabled></el-date-picker>
							</el-form-item>
							<el-form-item label="申请部门:">
								<el-input v-model="form.sdname" autocoplete="off" disabled></el-input>
							</el-form-item>
							<el-form-item label="备注信息:">
								<el-input v-model="form.infro" autocoplete="off" disabled></el-input>
							</el-form-item>
								<el-input v-model="form.end_date" autocoplete="off" type="hidden"></el-input>
								<el-input v-model="form.predno" autocoplete="off" type="hidden"></el-input>
								<el-input v-model="form.subdno" autocoplete="off" type="hidden"></el-input>
								<el-input v-model="form.state" autocoplete="off" type="hidden"></el-input>
								<el-input v-model="form.type" autocoplete="off" type="hidden"></el-input>
							<el-button type="success" @click="agree()">同意</el-button>
							<el-button type="danger" @click="disagree()">不同意</el-button>
						</el-form>
					</el-dialog>
				</el-tab-pane>
			</el-tabs>
		</el-row>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				
				me:this.$parent.$parent.$parent.$parent.emp,
				changes:[],
				dialogFormVisible:false,
				form:{
					changeno:'',
					type:'',
					eid:'',
					predno:'',
					subdno:'',
					change_date:'',
					end_date:'',
					infro:'',
					sdname:'',
					state:'',
				},
				myindex:-1,
				statex:0,
				};
		},
		created(){
		
			this.$axios.post("showdtransfer?eid="+this.me.eid+"").then(v=>{
				console.log(v)
				if(v.data){
						this.changes=v.data;
				}else{
					alert("出错了！！");
				}
			}).catch(ex=>{
				alert("出错了！"+ex);
			}) 
			
			this.$axios.post("showdtransferout?eid="+this.me.eid+"").then(v=>{
				console.log(v)
				if(v.data){
					if(JSON.stringify(this.changes)!="[]"){
						this.changes.push(v.data);
					}else{
						this.changes=v.data;
					}
				}else{
					alert("出错了！！");
				}
			}).catch(ex=>{
				alert("出错了！"+ex);
			})
			
		},
		methods:{
			look(index,row){
				var mydate=new Date();
				this.dialogFormVisible=true;
				this.form={
					changeno:row.changeno,
					type:row.type,
					eid:row.eid,
					predno:row.predno,
					subdno:row.subdno,
					sdname:row.sdname,
					change_date:row.change_date,
					end_date:'',
					infro:row.infro,
					state:row.state,
				}
				this.myindex=index;
			},
			agree(){
				this.dialogFormVisible=true;
				if(this.form.state==0){
					this.$axios.post("agrtransferlc",this.form).then(v=>{
						console.log(v)
						if(v.data){
							alert("申请处理成功！！");
						}else{
							alert("出错了！！");
						}
					}).catch(ex=>{
						alert("出错了！"+ex);
					})
				}else if(this.form.state==1){
					this.$axios.post("agrtransfernw",this.form).then(v=>{
						console.log(v)
						if(v.data){
							alert("申请处理成功！！");
						}else{
							alert("出错了！！");
						}
					}).catch(ex=>{
						alert("出错了！"+ex);
					})
				}
				
				this.form={
					changeno:'',
					type:'',
					eid:'',
					predno:'',
					subdno:'',
					change_date:'',
					end_date:'',
					infro:'',
					state:'',
				}
				var tos=this.$parent.$parent.$parent.$parent.todos;
				tos.forEach((v)=>{
					if(v.type==25){
						if(v.num>1){
							v.num=v.num-1;
						}else{
							tos.splice(v,1);
						}					
					}
				})
				this.changes.splice(this.myindex,1);
				this.myindex=-1;
				this.dialogFormVisible=false;
			},
			disagree(){
				
				this.dialogFormVisible=true;
				if(this.form.state==0){
					this.$axios.post("distransferlc",this.form).then(v=>{
						console.log(v)
						if(v.data){
							alert("申请处理成功！！");
						}else{
							alert("出错了！！");
						}
					}).catch(ex=>{
						alert("出错了！"+ex);
					})
				}else{
					this.$axios.post("distransfernw",this.form).then(v=>{
						console.log(v)
						if(v.data){
							alert("申请处理成功！！");
						}else{
							alert("出错了！！");
						}
					}).catch(ex=>{
						alert("出错了！"+ex);
					})
				}
				
				this.form={
					changeno:'',
					type:'',
					eid:'',
					predno:'',
					subdno:'',
					change_date:'',
					end_date:'',
					infro:'',
					state:'',
				}
				var tos=this.$parent.$parent.$parent.$parent.todos;
				tos.forEach((v)=>{
					if(v.type==25){
						if(v.num>1){
							v.num=v.num-1;
						}else{
							tos.splice(v,1);
						}					
					}
				})
				this.myindex=-1;
				this.changes.splice(this.myindex,1,this.form);
				this.dialogFormVisible=false;
			}
		}
	}
</script>

<style>

</style>
